package avicit.bdp.dms.tdm.service;


import avicit.bdp.common.base.BaseService;
import avicit.bdp.common.utils.redis.RedisCacheHelper;
import avicit.bdp.core.util.json.JSONUtils;
import avicit.bdp.dms.tdm.utils.TdmConstants;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.commons.utils.PojoUtil;
import avicit.platform6.core.properties.PlatformConstant;
import avicit.platform6.modules.system.syslog.service.SysLogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import avicit.bdp.dms.tdm.dto.ApiSettingDTO;
import avicit.bdp.dms.tdm.dao.ApiSettingDAO;


/** 
 * 资产API服务安全设置表服务
 *
 */
@Transactional
@Service
public class ApiSettingService extends BaseService<ApiSettingDAO, ApiSettingDTO> {

    @Autowired
    private RedisCacheHelper redisCacheHelper;

    public void save(ApiSettingDTO dto) {
        //先删除
        this.mapper.deleteByAssetId(dto.getAssetId());
        dto.setId(ComUtil.getId());
        PojoUtil.setSysProperties(dto, PlatformConstant.OpType.insert);
        this.insert(dto);
        //添加到redis
        redisCacheHelper.set(TdmConstants.ASSET_API_SETTING + dto.getAssetId(),
                JSONUtils.toJsonString(dto));
        // 记录日志
        SysLogUtil.log4Insert(dto);
    }

    public ApiSettingDTO queryByAssetId(String assetId) {
        return this.mapper.queryByAssetId(assetId);
    }
}